package slent.iespana.es.visualizacion;

import java.util.Random;
import java.awt.Frame;
import javax.media.opengl.GL;
import com.sun.opengl.util.GLUT;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import java.util.Random;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionListener;

public class Particulas {

    float position[] = new float[3];
    float velocity;
    float size;
    Particulas2 par[] = new Particulas2[250];
    boolean prim = true, prim1 = true;
    float color[] = new float[3];
//float trans;
    Random rnd = new Random();
    float lifetime;

    Particulas() {
    }

    Particulas(float a[], float b, float g, float c[], float d) {
        position[0] = a[0];
        position[1] = a[1];
        position[2] = a[2];
        velocity = b;
        size = g;
        color[0] = c[0];
        color[1] = c[1];
        color[2] = c[2];
        lifetime = d;
    }

    public float[] nuevaPos(float po[]) {
        po[0] += ((float) rnd.nextDouble() % .005f);
        po[1] = ((float) rnd.nextDouble() % .05f);
        po[2] = ((float) rnd.nextDouble() % .05f);
        //System.out.println("po0="+po[0]);
        return po;
    }

    public float[] nuevaPos2(float po[]) {
        po[0] -= ((float) rnd.nextDouble() % .2f);
        po[1] = ((float) rnd.nextDouble() % .05f);
        po[2] = ((float) rnd.nextDouble() % .05f);
        //System.out.println("po0="+po[0]);
        return po;
    }

    public void Enlace(GL gl, boolean prim2) {
        /////////////////////sistemas de particulas///////////

        if (prim == true) {

            float col[] = {1.0f, 1.0f, 1.0f};
            float pos[] = {-0.3f, 0, 0};
            for (int x = 0; x < 150; x++) {
                par[x] = new Particulas2(pos, 1.0f, 0.005f, col, 1.0f);
                pos[0] += 0.005f;
            }//////fin for
        }
        prim = false;
        if (prim1 == true) {
            ///////////////////////////////////////////////////////
            for (int x = 0; x < 150; x++) {
                if (prim2 == true) {
                    if (par[x].position[0] < 0.4f) {
                        par[x].position = nuevaPos(par[x].position);
                    }//////fin if
                    //	System.out.println("po0="+ par[x].position[0]);
                    //if(par[x].position[0]<-0.2f)
                    else {
                        //gl.glTranslated(-.05f,0f,0f);
                        par[x].position[0] = ((float) rnd.nextDouble() % +.38f) + .3f;
                        par[x].position[1] = ((float) rnd.nextDouble() % ((3 / 4) * (3.1416f) * (0.15f * 0.15f * 0.15f)));
                        par[x].position[2] = ((float) rnd.nextDouble() % ((3 / 4) * (3.1416f) * (0.15f * 0.15f * 0.15f)));
                    }/////fin else
                }////fin if
                gl.glColor3f(1, 1, 1);
                gl.glBegin(GL.GL_LINES);
                gl.glVertex3f(par[x].position[0], par[x].position[1], par[x].position[2]);
                gl.glVertex3f(par[x].position[0] + 0.005f, par[x].position[1], par[x].position[2]);
                gl.glEnd();
                /////////////////////////////////////////////////
            }///////fin for

        }
    }

    public void Ori() {
        float col[] = {1.0f, 1.0f, 1.0f};
        float pos[] = {-0.3f, 0, 0};
        for (int x = 0; x < 150; x++) {
            par[x] = new Particulas2(pos, 1.0f, 0.005f, col, 1.0f);
            pos[0] += 0.005f;
        }//////fin for

    }
}
